import React from 'react'
import { connect } from 'react-redux'
import { push } from 'connected-react-router'
import PropTypes from 'prop-types'
import { projectLabelView as projectDuck } from 'ducks'

class GetListTypeView extends React.Component {
  static propTypes = {
    defalutListType: PropTypes.string,
    redirect: PropTypes.func.isRequired,
    match: PropTypes.object.isRequired,
  }

  static defaultProps = {
    defalutListType: undefined,
  }

  componentDidMount() {
    const { redirect, defalutListType, match } = this.props
    if (defalutListType !== undefined) {
      redirect(`${match.url}/${defalutListType}`)
    } else {
      redirect(`${match.url}/nowork`)
    }
  }

  render() {
    return null
  }
}

const mapStateToProps = state => ({
  defalutListType: projectDuck.selectors.defaultImageListType(state),
})

const mapDispatchToProps = {
  redirect: push,
}

export default connect(mapStateToProps, mapDispatchToProps)(GetListTypeView)
